﻿import com.dmotiko.zonaoutlet.*
import com.dmotiko.general.*
import mx.utils.Delegate;

class ZOPromocionItem
extends BaseClip {
	
	private var mcIcon:PhotoClip;
	private var mcSeparator:MovieClip;
	private var txtContent:TextField;
	private var mcDownloadPDF:ZOPromocionDownload;
	
	private function initClip():Void {
		txtContent.autoSize = "left";
	}
	
	private function refreshData():Void {
		txtContent.text = data.description;
		mcDownloadPDF._visible = data.download;
		mcDownloadPDF._y = txtContent._y + txtContent._height + 5;
		mcSeparator._y = mcDownloadPDF._y + mcDownloadPDF._height - 5;
	}
	
	public function childLoaded( evnt ):Void {
		if ( evnt.target == mcIcon ) {
			mcIcon.setData( data.outlet.logoSrc );
			mcIcon.addEventListener( BaseClipEvent.READY, Delegate.create( this, icon_loaded ) );
		} else if ( evnt.target == mcDownloadPDF) {
			mcDownloadPDF.addEventListener( BaseClipEvent.CHANGED, Delegate.create(this, download_pdf) );
		}
	}
	
	private function icon_loaded( evnt ):Void {
		var root = this;
		mcIcon._y = (txtContent._y - mcIcon._height) / 2;
		mcIcon.onRelease = function() {
			ZOSite.getApp().setActiveOutlet( root.getData().outlet );
			ZOSite.getApp().setSection( ZOSite.BUSCADOR );
		}
	}
	
	private function download_pdf( evnt ):Void {
		getURL( data.download, "_blank" );
	}

}